import 'dart:math';

import 'package:fluttercalcpokers/odds/bean/card_bean.dart';

///涉及到业务的常用方法
class BizUtils {
  static List<CardBean> alreadyCards = new List();
  static List<CardBean> allCards = CardBean.getAllCards();

  static void clearCards() {
    alreadyCards.clear();
  }

  static void addCards(List<CardBean> list) {
    alreadyCards.addAll(list);
  }

  static void addCard(CardBean card) {
    if (card == null) return;
    alreadyCards.add(card);
  }

  static bool isExitCard(CardBean card) {
    for (var bean in alreadyCards) {
      if (CardBean.isSame(card, bean)) {
        return true;
      }
    }
    return false;
  }

  static List<CardBean> randomCards(int count) {
    var rng = new Random();
    List<CardBean> results = new List();
    for (var i = 0; i < count; i++) {
      var index;
      CardBean card;
      do {
        index = rng.nextInt(52);
        card = allCards[index];
      } while (isExitCard(card));
      results.add(card);
      alreadyCards.add(card);
    }
    return results;
  }
}
